package com.baosu.test;

import org.springframework.util.AntPathMatcher;

public class Path {

    //spring提供的API
    public static final AntPathMatcher PATH_MATCHER = new AntPathMatcher();

    /**
     * 路径匹配，检查本次请求是否需要放行
     * @param urls
     * @param requestURI
     * @return
     */
    public static boolean check(String[] urls,String requestURI){
        for (String url : urls) {
            boolean match = PATH_MATCHER.match(url, requestURI);
            if(match){
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        //定义不需要处理的请求路径
        String[] urls = new String[]{
                "/employee/login",
                "/employee/logout",
                "/backend/**",
                "/front/**",
                "/front/page/**"
        };

        //判断本次请求是否需要处理
        String requestURI = "/employee/login";
        boolean check = Path.check(urls, requestURI);
        System.out.println(check); //true
    }


}
